<?php
require 'page.class.php';
$gid=$_GET['gid'];
$connect=mysql_connect("localhost","root","192510");
mysql_select_db("news",$connect);
//根据gid得到所有的用户
$sql3="select * from guanxi where gid=$gid";
$result3=mysql_query($sql3);
$yonghu=array();


$sql2="select count(*) as amount from shouzhong";
$result=mysql_query($sql2);
$row=mysql_fetch_array($result);
$count=$row['amount'];//总条数
$pagesize=10;//每页显示的条数

if($count%$pagesize){
	$page=ceil($count/$pagesize);
}else{
	$page=$count/$pagesize;
}
if(isset($_GET['currentpage'])){
	$currentpage=intval($_GET['currentpage']);
}else{
	$currentpage=1;
}
$start=($currentpage-1)*$pagesize;
$sql="select * from shouzhong limit $start,$pagesize";
$result = mysql_query($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-1.6.3.min.js"></script>
<style>
      .tip{
		  width:600px;
		  height:500px;
	  }
	  
</style>

<script type="text/javascript">
$(document).ready(function(){
  $(".click").click(function(){
  $(".tip").fadeIn(200);
  });
  
  $(".tiptop a").click(function(){
  $(".tip").fadeOut(200);
});

  $(".sure").click(function(){
  $(".tip").fadeOut(100);
});

  $(".cancel").click(function(){
  $(".tip").fadeOut(100);
});

});
</script>
</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">接收受众</a></li>
    <li><a href="#">受众列表</a></li>
    </ul>
    </div>
    
    <div class="rightinfo">
	
    <table class="tablelist">
    	<thead>
    	<tr>
        <th><input type="checkbox" name="checkbox11" id="checkbox11"onclick="selectAll(this)"/></th>
        <th>名称</i></th>
        <th>类型</th>
        <th>邮箱</th>
        <th>licesneID</th>
        <th>备注</th>
        <th>基本操作</th>
        </tr>
        </thead>
		
        <tbody>
	    <?php
		while($row=mysql_fetch_array($result)){
		?>
		<tr>
        <td> <input type="checkbox" name="checkbox1" id="checkbox1<?php echo $row['id']; ?>" value="<?php echo $row['id'];?>" onclick="guanxi('<?php echo $row['id'];?>','<?php echo $gid;?>');"/></td>
        <td><?php echo $row['name']; ?></td>
        <td><?php if($row['type']==0){echo "用户";}else{ echo "机器";}?></td>
        <td><?php echo $row['email'];?></td>
        <td><?php echo $row['licesneID'];?></td>
        <td><?php echo $row['beizhu'];?></td>
        <td><a onclick="ck('<?php echo $row['id'];?>')" href="#" class="tablelink">查看</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="delete_shouzhong.php?id=<?php echo $row['id'];?>" class="tablelink">删除</a></td>
        </tr>		
		<?php 
		}
		?>
        </tbody>
    </table>
	
    <div class="pagin">
    	<?php 
    		pagelinks();
    	?>
    </div>
	
	<div onclick="fanhui();" style="margin-left:1200px;margin-top:30px;"><input  type="button" class="loginbtn" value="返回群列表"/></div>
	
     
    </div>
    
    <script type="text/javascript">
	
	function fanhui(){
		 location.href = "select_group.php";
		
	}
	
	
                   //用来回显
        $(document).ready(function(){
			 //勾选群下的所有的用户
			 //得到该群下的用户的数组
			 var ss=new Array();
			<?php  while($row3=mysql_fetch_array($result3)){		  
            ?>
			 ss.push(<?php echo $row3['sid']; ?>); 
			<?php } ?>
			
		   for(var i=0;i<ss.length;i++){
			 $("#checkbox1"+ss[i]).attr("checked",true);
		   }
	   })
	   
	   
	  
	function selectAll(objs)
    {
    obj=document.getElementsByName('checkbox1');
    for(var i=0;i<obj.length;i++){
	if(objs.checked){
		obj.item(i).checked=true;
	}else{
		obj.item(i).checked=false; 
	}  
  }
}
	  
	 function guanxi(sid,gid){
		 //判断checkbox是否被选中,如果被选择，怎让type为1,去添加数据
		var obj=document.getElementsByName('checkbox1');
	    if($('#checkbox1'+sid).is(':checked')){
			//被选中则需要去添加数据  去数据库添加
		$.post("insert_guanxi_commit.php",
		 {
			sid:sid,
			gid:gid
		},
		 function(data){
			
		  })
		  
		}else{//去数据库删除
		 $.post("delete_guanxi.php",
		 {
			sid:sid,
			gid:gid
		 },
		 function(data){
			 
		  })
		}
		
	   }
	  
	  
		

	</script>
</body>
</html>
